//这两个包都在util下面，可以直接写成*
import jdk.nashorn.internal.ir.SplitReturn;

import java.util.*;
import java.sql.*;
import static java.lang.Math.*;
/*import java.util.Arrays;
import java.util.Date;*/

class Student3 {
    private String name;//普通成员变量
    private int age;
    //定义成static后，教室只有一份了，否则，每个对象都有一份教室
    static String classRoom = "301";//类成员/静态成员变量 所有对象共用只有一份
    //设置姓名，获取姓名
    //设置公开的接口提供类外使用，以达到封装的效果
    //自动生成，右键->Generate->geterAndseter->选择要创建的字段
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return this.name;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public int getAge() {
        return this.age;
    }

    public void doClass() {
        System.out.println(this.name+" 上课");
        this.print();
    }

    public Student3() {
        /*this.name = "yxj";
        this.age = 17;*/
        //this("yxj",17);
        System.out.println("不带参数的构造方法");
    }
    public Student3(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("带2个参数的构造方法");
    }

    public Student3(String name, int age, String classRoom) {
        this.name = name;
        this.age = age;
        this.classRoom = classRoom;
    }

    public void print() {
//        funcStatic();
        System.out.println("姓名："+this.name+"年龄："+this.age);
        {
            System.out.println("普通代码块：定义在方法中的代码块，没有实际意义和作用");
        }
    }
    //static修饰成员方法，类方法/静态成员方法
    //不依赖对象，可以使用类名调用
    //静态方法内部不能够调用非静态方法，因为静态方法不依赖对象，非静态方法依赖对象
    public static void funcStatic() {
        //print();
        System.out.println("funcStatic()");
    }
}

class Student4 {
    private String name;
    private int age;

    //静态成员变量使用静态代码块初始化静态成员变量
    private static String classRoom;
/*    static {
        classRoom = "302";
        System.out.println("静态代码块");
    }*/

    public static String getClassRoom() {
        return classRoom;
    }

    public static void setClassRoom(String classRoom) {
        Student4.classRoom = classRoom;
    }

    public Student4() {
        System.out.println("调用了不带参数的构造方法");
    }
    public Student4(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("调用了带2个参数的构造方法");
    }

    //实例(构造)代码块初始化非静态成员变量
/*    {
        //this.name = "yxj";
        System.out.println("实例（构造）代码块");
    }*/

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void print() {
        System.out.println("姓名："+name+ " 年龄："+age);
    }

/*    public String toString() {
        return "姓名："+name+ " 年龄："+age;
    }*/

    @Override
    public String toString() {
        return "Student4{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class TestDate {
    public static void main(String[] args) {
        Student4 student1 = new Student4("zhangs",12);
        //student1.print();
        System.out.println(student1);
        //Student4 student1 = new Student4("yxj",23);
        //System.out.println(Student4.getClassRoom());
    }
    public static void main4(String[] args) {
        Student3.funcStatic();
//        Student3 student1 = new Student3("zhangsan",12);
//        Student3 student2 = new Student3("lisi",13);
//        Student3 student3 = new Student3("wangwu",14);
//        System.out.println("教室是："+Student3.classRoom);
//        System.out.println(student1.classRoom);
    }
    public static void main3(String[] args) {
        Student3 student3 = new Student3();
        //student3.name = "yxj";
        student3.setName("yxj");
        //student3.age = 13;
        student3.setAge(11);
        System.out.println(student3.getName());
        System.out.println(student3.getAge());
        student3.print();
    }
    public static void main2(String[] args) {
        //这种写法比较麻烦，可以使用import语句导入包:import java.util.Date;
        //Date date = new Date();
        java.util.Date date = new java.util.Date();
        //System.out.println(date.getTime()); //得到一个时间戳

/*        int[] array = new int[]{5,4,3,2,1};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));*/

        double x = 10;
        double y = 20;
        //静态导入的包可以有下面2种写法
        //double result = Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
        double result2 = sqrt(pow(x,2)+pow(y,3));
    }

    public static void main1(String[] args) {
        Student2 student2 = new Student2();
        //student1.doClass();
/*        student2.name = "yxj";
        student2.age = 19;*/
        student2.print();
    }
}

class TestDate1 {
    public int year = 2023;
    public int month = 9;
    public int day;

    //构造方法：构造方法可以重载
    //构造方法意义，在构造对象的同时给指定变量赋值
   public TestDate1() {
       //当我们没有写构造方法时，编译器会默认帮我们写一个什么都没有的构造方法
        System.out.println("没有参数的构造方法");
    }

    public TestDate1(int year, int month) {
        this.year = year;
        this.month = month;
    }

    //构造方法可以重载
    //如果自己写有构造方法，则编译器不会帮助我们写构造方法了
    public TestDate1(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
        System.out.println("有3个参数的构造方法");
    }
    public void setDate(TestDate1 this, int year, int month, int day) {
        //局部变量和全局变量同时出现时，局部优先
        //这里是给局部变量自己赋值，并没有给到成员变量赋值
        //所以就用到了this，谁调用了setDate这个this就是谁,this就是当前对象的引用
        this.year = year;
        this.month = month;
        this.day = day;
    }
    public void printDate(TestDate1 this) {
        System.out.println("年："+this.year+" 月："+this.month+" 日："+this.day);
    }

    public static void main(String[] args) {
/*        int a;
        System.out.println(a);//报错，局部变量必须先初始化然后再使用*/
        TestDate1 testDate1 = new TestDate1(1999,3,4);
        TestDate1 testDate2 = new TestDate1(2000,1,23);
        TestDate1 testDate3 = new TestDate1();
/*        testDate1.setDate(2000, 1, 4);
        testDate2.setDate(2001,10,14);
        testDate3.setDate(2002,3,24);*/
        testDate1.printDate();
        testDate2.printDate();
        testDate3.printDate();

    }
}

class Student1 {
    public String name = "yxj";
    public int age = 80;

    //两个构造方法名字相同，参数列表不同，因此构成了方法重载
    public Student1() {
        /*this.name = "yxj";
        this.age = 17;*/
        //this("yxj",17);
        System.out.println("不带参数的构造方法");
    }
    public Student1(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("带2个参数的构造方法");
    }
    public void doClass() {
        System.out.println(this.name+" 上课");
        this.print();
    }
    public void print() {
        System.out.println("姓名："+this.name+"年龄："+this.age);
    }

    public static void main(String[] args) {
        Student1 student1 = new Student1();
        //student1.doClass();
        student1.print();
    }
}

//封装--关键字：private
//想隐藏我的实现细节，不想让类外看到我的细节，就可以使用封装实现
class Student2 {
    private String name;
    private int age;

    //两个构造方法名字相同，参数列表不同，因此构成了方法重载
    public Student2() {
        /*this.name = "yxj";
        this.age = 17;*/
        //this("yxj",17);
        System.out.println("不带参数的构造方法");
    }
    public Student2(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("带2个参数的构造方法");
    }
    public void doClass() {
        System.out.println(this.name+" 上课");
        this.print();
    }
    public void print() {
        System.out.println("姓名："+this.name+"年龄："+this.age);
    }

    public static void main(String[] args) {
        Student2 student2 = new Student2();
        //student1.doClass();
        student2.name = "yxj";
        student2.age = 19;
        student2.print();
    }
}



